﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

namespace WindowPlace
{
    /// <summary>
    /// Interaction logic for WindowInfoDialog.xaml
    /// </summary>
    public partial class WindowInfoDialog : Window
    {


        public bool IsAdding
        {
            get { return (bool)GetValue(IsAddingProperty); }
            set { SetValue(IsAddingProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsAdding.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsAddingProperty =
            DependencyProperty.Register("IsAdding", typeof(bool), typeof(WindowInfoDialog), new UIPropertyMetadata(false));



        public bool IsEditing
        {
            get { return (bool)GetValue(IsEditingProperty); }
            set { SetValue(IsEditingProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsEditing.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsEditingProperty =
            DependencyProperty.Register("IsEditing", typeof(bool), typeof(WindowInfoDialog), new UIPropertyMetadata(true));

        


        public WindowInfo WindowInfo
        {
            get { return (WindowInfo)GetValue(WindowInfoProperty); }
            set { SetValue(WindowInfoProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WindowInfo.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WindowInfoProperty =
            DependencyProperty.Register("WindowInfo", typeof(WindowInfo), typeof(WindowInfoDialog), new UIPropertyMetadata(null));

        public WindowInfoDialog(WindowInfo WindowInfo, bool Adding)
        {
            InitializeComponent();
            this.IsAdding = Adding;
            this.IsEditing = !Adding;
            this.WindowInfo = WindowInfo;
            //Debug.Print("   WindowInfoDialog.DataContext set to {0}", WindowInfo.ToString());
            this.DataContext = this;
        }

        //private void GetCurrentLocation_Click(object sender, RoutedEventArgs e)
        //{
        //    this.WindowInfo.CurrentRectangle = WindowPlace.Common.Common.GetWindowRectangle(this.WindowInfo.hWnd);
        //}

        private void Close_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void SetToCurrentPosition_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            this.WindowInfo.CurrentRectangle = WindowPlace.Common.Helper.GetWindowRectangle(this.WindowInfo.hWnd);
        }

        private void SetToCurrentPosition_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Parameter != null && e.Parameter.GetType() == typeof(WindowInfo))
            {
                e.CanExecute = ((WindowInfo)e.Parameter).IsFound;
            } else e.CanExecute = false;
        }
    }
}
